package services;

import java.util.LinkedList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.aton.db.SessionFactory;

import models.Region;
import models.mappers.RegionMapper;

public class RegionService {
	/**
	 * 获取节点数据
	 *
	 * @Title: getRegion 
	 * @param pid
	 * @return
	 * @return: List<Region>
	 */
	public static LinkedList<Region> getRegion(String pid) {
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			RegionMapper mapper = ss.getMapper(RegionMapper.class);
            return mapper.getRegion(pid);
        } finally {
            ss.close();
        }
	}
	/**
	 * 获取根节点
	 *
	 * @Title: getFRegion 
	 * @param pid
	 * @return
	 * @return: List<Region>
	 */
	public static LinkedList<Region> getFRegion() {
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			RegionMapper mapper = ss.getMapper(RegionMapper.class);
            return mapper.getFRegion();
        } finally {
            ss.close();
        }
	}
	/**
	 * 根据id查询地区
	 *
	 * @Title: getById 
	 * @param id
	 * @return: void
	 */
	public static Region getById(String id){
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			RegionMapper mapper = ss.getMapper(RegionMapper.class);
            return mapper.getById(id);
        } finally {
            ss.close();
        }
	}

}
